<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:pe="http://primefaces.org/ui/extensions"
	template="/WEB-INF/templates/template.xhtml">
	
	<ui:define name="headIncludes">
		<f:event listener="#{contaReceberBean.initializeForm(param.contaReceberId)}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">Dar baixa em Conta a Receber</ui:define>
	<ui:define name="buttons">
		<p:commandButton value="Dar baixa" style="height:28px;" action="#{contaReceberBean.darBaixaContaReceber}"  rendered="#{contaReceberBean.currentConta.id != null and contaReceberBean.currentConta.status != 'PAGA'}" icon="ui-icon-check"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{contaReceberBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>			
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages autoUpdate="true" closable="true"/>
				
				<h:panelGrid columns="1" style="padding:5px;" id="panelCliente">
					<h:outputText style="padding:7px;" value="Cliente" />
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.cliente.nome}"/>
				</h:panelGrid>
				
				<h:panelGrid columns="5" style="padding:5px;">
					<h:outputText style="padding:7px;" value="Nº do documento" />
					<h:outputText style="padding:7px;" value="Descrição" />
					<h:outputText style="padding:7px;" value="Data de emissão" />
					<h:outputText style="padding:7px;" value="Valor" />
					<h:outputText style="padding:7px;" value="Data de vencimento" />
					
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.id}"/>
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.descricao}"/>
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.dataEmissao}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.valor}">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.dataVencimento}">
						<f:convertDateTime pattern="dd/MM/yyyy"/>
					</h:outputText>
				</h:panelGrid>
				
				<h:panelGrid columns="6" style="padding:5px;">
					<h:outputText value="Multa (R$)" />
					<h:outputText value="Juros (%)" />
					<h:outputText value="Desconto (R$)" />
					<h:outputText value="Desconto (%)" />
					<h:outputText value="Data de pagamento" />
					<h:outputText value="Valor total"/>

					<pe:inputNumber style="width:100px;" value="#{contaReceberBean.currentConta.multa}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputMulta" maxValue="1000000"
						disabled="#{(contaReceberBean.currentConta.descontoValor != null and contaReceberBean.currentConta.descontoValor > 0) 
										or (contaReceberBean.currentConta.descontoPercentual != null and contaReceberBean.currentConta.descontoPercentual > 0)}">
						<p:ajax event="change" update="inputDescontoValor, inputDescontoPercent" listener="#{contaReceberBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaReceberBean.currentConta.juros}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputJuros" 
						disabled="#{(contaReceberBean.currentConta.descontoValor != null and contaReceberBean.currentConta.descontoValor > 0) 
										or (contaReceberBean.currentConta.descontoPercentual != null and contaReceberBean.currentConta.descontoPercentual > 0)}"
						maxValue="100">
						<p:ajax event="change" update="inputDescontoValor, inputDescontoPercent" listener="#{contaReceberBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaReceberBean.currentConta.descontoValor}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputDescontoValor" maxValue="1000000"
						disabled="#{(contaReceberBean.currentConta.multa != null and contaReceberBean.currentConta.multa > 0) 
										or (contaReceberBean.currentConta.juros != null and contaReceberBean.currentConta.juros > 0)
										or (contaReceberBean.currentConta.descontoPercentual != null and contaReceberBean.currentConta.descontoPercentual > 0)}">
						<p:ajax event="change" update="inputDescontoPercent, inputMulta, inputJuros" listener="#{contaReceberBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<pe:inputNumber style="width:100px;" value="#{contaReceberBean.currentConta.descontoPercentual}" decimalSeparator="," decimalPlaces="2"  thousandSeparator="." id="inputDescontoPercent"
						disabled="#{(contaReceberBean.currentConta.multa != null and contaReceberBean.currentConta.multa > 0) 
										or (contaReceberBean.currentConta.juros != null and contaReceberBean.currentConta.juros > 0)
										or (contaReceberBean.currentConta.descontoValor != null and contaReceberBean.currentConta.descontoValor > 0)}"
						maxValue="100">
						<p:ajax event="change" update="inputDescontoValor, inputMulta, inputJuros" listener="#{contaReceberBean.handleInputValorChange}"/>
					</pe:inputNumber>
					
					<p:calendar style="width:100px;" showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" navigator="true" readonlyInput="true"
						value="#{contaReceberBean.currentConta.dataPagamento}" id="inputDataPagamento" mindate="#{contaReceberBean.currentConta.dataEmissao}"/>				
					
					<h:outputText style="padding:7px;" value="#{contaReceberBean.currentConta.valorPago}" id="inputValorPago">
						<f:convertNumber pattern="R$ #,###,##0.00" />
					</h:outputText>
				</h:panelGrid>
			</div>
		</p:panel>		
	</ui:define>
</ui:composition>